package ch.hoth.java.joocal.actions;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.ProgressBar;

import ch.hoth.java.joocal.CalendarController;
import ch.hoth.java.joocal.ui.StatusLineManager;

public class LoadAction extends CalendarAction {
	
	public LoadAction(CalendarController controller){
		super("load", controller);
	}
	
	

	@Override
	public void run() {
		
		IProgressMonitor monitor = StatusLineManager.getPlaceHolder();
		monitor.beginTask("Loading xml", 500);
		Thread t = new Thread(new Runnable(){
			public void run() {
				getController().load();
			}
		});
		t.start();
		
		while(true){
			try {
				monitor.worked(1);
	        	Thread.sleep(1); // 1ms
	        	if (!t.isAlive()){
	        		break;
	        	}
	        }
			catch(Exception e){
	        	// do nothing
	        }
		}
		
		monitor.done();	      

		/*
		try{ Thread.sleep(3000);}catch (Exception e) {
			// TODO: handle exception
		}
		getController().load();
		StatusLineManager.getPlaceHolder().done();*/
	}

	
}
